(function(){
	var id,
		$name,
		$savePath,
		$createTime,
		$redEnclosure,
		$redFile,
		$delFile,
		$delEnclosure,
		$modForm;
	
	$(function(){
		id=window.location.hash.substr(1);
		
		$name=$("#nameEL");
		$savePath=$("#savePathEL");
		$createTime=$("#createTimeEL");
		$modForm=$("#modForm");
		
		$redEnclosure=$("#redEnclosure")
		$redFile=$("#redFile")
		$delFile=$("#delFile")
		$delEnclosure=$("#delEnclosure");
		
		loadModel(id);
	})
		
	var loadModel=function(id){
		var url="/api/document/rec/check?id="+id;
		$.get(url,function(resp){
			if(resp.code==="ok"){
				console.log(resp.data);
				paint(resp.data);
			}else{
				toast(resp.message);
			}
		})
	};
	var  paint=function(m){
		$name.val(m[0].name);
		$savePath.val($$(m[0].savePath));
		$createTime.val(Date.format(m[0].createTime));
		p(m[0].isDirectory,m[0].parentId);
	}
	
	var p=function(a,b){
		if(a===0&&b!==null){
			$redFile.hide(); 
			$delFile.hide();
			$redEnclosure.click(restoreClick);
			$delEnclosure.click(deleteClick);
		}else{
			$redEnclosure.hide(); 
			$delEnclosure.hide();
			$redFile.click(restoreClick);
			$delFile.click(deleteClick);
		}
	}
	
	var restoreClick=function(evt){
		evt.preventDefault();
		var url="/api/document/rec/red?id="+id;
		$.get(url,function(resp){
			if(resp.code=="ok"){
				toast("还原成功");
			}
		})
	}
	
	var deleteClick=function(evt){
		evt.preventDefault();
		var url="/api/document/rec/del?id="+id;
		$.get(url,function(resp){
			if(resp.code==="ok"){
				toast("删除成功");
			}
		})
	}
})()
